<template>
  <div v-if="searchType == 1" class="search bar1 search-main">
    <form>
      <input
        v-model="searchText"
        type="text"
        placeholder="请输入您要搜索的内容..."
      />
      <button type="button" @click="handleSearch"></button>
    </form>
  </div>
  <div v-else-if="searchType == 2" id="container" class="search-main">
    <div class="search bar2">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
  <div v-else-if="searchType == 3" id="container" class="search-main">
    <div class="search bar3">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
  <div v-else-if="searchType == 4" id="container" class="search-main">
    <div class="search bar4">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
  <div v-else-if="searchType == 5" id="container" class="search-main">
    <div class="search bar5">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
  <div v-else-if="searchType == 6" id="container" class="search-main">
    <div class="search bar6">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
  <div v-else-if="searchType == 7" id="container" class="search-main">
    <div class="search bar7">
      <form>
        <input
          v-model="searchText"
          type="text"
          placeholder="请输入您要搜索的内容..."
        />
        <button type="button" @click="handleSearch"></button>
      </form>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();

// Props
const props = defineProps({
  searchType: {
    type: [Number, String],
    default: 3,
  },
});

// Data
const searchText = ref<string>("");

// Methods
const handleSearch = () => {
  router.push({
    path: "/classify",
    query: { searchText: searchText.value },
  });
};
</script>

<style scoped lang="less">
.search-main {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-left: 20px;
}

* {
  box-sizing: border-box;
}

div.search {
  display: flex;
  flex-direction: row;
  align-items: center;
  margin-left: 20px;
}

form {
  position: relative;
  width: 300px;
  margin: 0 auto;
}

input,
button {
  border: none;
  outline: none;
}

input {
  width: 100%;
  height: 42px;
  padding-left: 13px;
}

button {
  height: 42px;
  width: 42px;
  cursor: pointer;
  position: absolute;
}

/* Search box styles */
.bar1 input {
  border: 2px solid #7ba7ab;
  border-radius: 5px;
  background: #f9f0da;
  color: #9e9c9c;
}
.bar1 button {
  top: 0;
  right: 0;
  background: #7ba7ab;
  border-radius: 0 5px 5px 0;
}
.bar1 button:before {
  content: "\f002";
  font-family: FontAwesome;
  font-size: 16px;
  color: #f9f0da;
}

.bar2 {
  background: #dabb52;
}
.bar2 input,
.bar2 button {
  border-radius: 3px;
}
.bar2 input {
  background: #f9f0da;
}
.bar2 button {
  height: 26px;
  width: 26px;
  top: 8px;
  right: 8px;
  background: #f15b42;
}
.bar2 button:before {
  content: "\f105";
  font-family: FontAwesome;
  color: #f9f0da;
  font-size: 20px;
  font-weight: bold;
}

.bar3 form {
  background: #a3d0c3;
}
.bar3 input,
.bar3 button {
  background: transparent;
}
.bar3 button {
  top: 0;
  right: 0;
}
.bar3 button:before {
  content: "\f002";
  font-family: FontAwesome;
  font-size: 16px;
  color: #f9f0da;
}

.bar4 form {
  background: #f9f0da;
  border-bottom: 2px solid #be290e;
}
.bar4 input,
.bar4 button {
  background: transparent;
}
.bar4 button {
  top: 0;
  right: 0;
}
.bar4 button:before {
  content: "\f178";
  font-family: FontAwesome;
  font-size: 20px;
  color: #be290e;
}

.bar5 input,
.bar5 button {
  background: transparent;
}
.bar5 input {
  border: 2px solid #f9f0da;
}
.bar5 button {
  top: 0;
  right: 0;
}
.bar5 button:before {
  content: "\f002";
  font-family: FontAwesome;
  font-size: 16px;
  color: #f9f0da;
}
.bar5 input:focus {
  border-color: #311c24;
}

.bar6 input {
  border: 2px solid #c5464a;
  border-radius: 5px;
  background: transparent;
  top: 0;
  right: 0;
}
.bar6 button {
  background: #c5464a;
  border-radius: 0 5px 5px 0;
  width: 60px;
  top: 0;
  right: 0;
}
.bar6 button:before {
  content: "搜索";
  font-size: 13px;
  color: #f9f0da;
}

.bar7 form {
  height: 42px;
}
.bar7 input {
  width: 250px;
  border-radius: 42px;
  border: 2px solid #324b4e;
  background: #f9f0da;
  transition: 0.3s linear;
  float: right;
}
.bar7 input:focus {
  width: 300px;
}
.bar7 button {
  background: none;
  top: -2px;
  right: 0;
}
.bar7 button:before {
  content: "\f002";
  font-family: FontAwesome;
  color: #324b4e;
}

.bar8 form {
  height: 42px;
}
.bar8 input {
  width: 0;
  padding: 0 42px 0 15px;
  border-bottom: 2px solid transparent;
  background: transparent;
  transition: 0.3s linear;
  position: absolute;
  top: 0;
  right: 0;
  z-index: 2;
}
.bar8 input:focus {
  width: 300px;
  z-index: 1;
  border-bottom: 2px solid #f9f0da;
}
.bar8 button {
  background: #683b4d;
  top: 0;
  right: 0;
}
.bar8 button:before {
  content: "\f002";
  font-family: FontAwesome;
  font-size: 16px;
  color: #f9f0da;
}
</style>
